package ravishankar.app.hindi2englishsms;

import gayatrirathore.app.adapter.HindiSmsCategoriesAdapter;
import gayatrirathore.app.adapter.SmsCategoriesAdapter;
import ravishankar.app.hindi2englishsms.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AnimationUtils;
import android.view.animation.LayoutAnimationController;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.ViewAnimator;

import com.tekle.oss.android.animation.AnimationFactory;
import com.tekle.oss.android.animation.AnimationFactory.FlipDirection;

public class MainActivity extends Activity {
	boolean isHindiSmsShow=true;
	  LayoutAnimationController controller;
ListView mSmsCategoriesListHindi,mSmsCategoriesListEnglish; 
String COUNTRIES[]=new String[]{"Afganistan","India","Pakistan","Shri Lanka","Bangladesh"};
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        
        
        
        final ViewAnimator viewAnimator = (ViewAnimator)this.findViewById(R.id.viewFlipper);
        mSmsCategoriesListHindi=(ListView)this.findViewById(R.id.lvSmsCategoriesHindi);
        mSmsCategoriesListEnglish=(ListView)this.findViewById(R.id.lvSmsCategoriesEnglish);
        mSmsCategoriesListHindi.setAdapter(new HindiSmsCategoriesAdapter(MainActivity.this));
        mSmsCategoriesListEnglish.setAdapter(new SmsCategoriesAdapter(MainActivity.this));
        
        controller = AnimationUtils.loadLayoutAnimation(
	         MainActivity.this, R.anim.list_layout_controller);
        
        mSmsCategoriesListHindi.setLayoutAnimation(controller);
	      mSmsCategoriesListEnglish.setLayoutAnimation(controller);
        
        this.findViewById(R.id.ivRotet).setOnClickListener(new OnClickListener() { 
			public void onClick(View v) { 
				// This is all you need to do to 3D flip
				
				 mSmsCategoriesListHindi.setLayoutAnimation(controller);
			      mSmsCategoriesListEnglish.setLayoutAnimation(controller);
				AnimationFactory.flipTransition(viewAnimator, FlipDirection.LEFT_RIGHT);
				 
			}
        	
        });
        
  
        mSmsCategoriesListEnglish.setTextFilterEnabled(true);
      
     
      
        mSmsCategoriesListHindi
		.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				Intent intent = new Intent(MainActivity.this,
						SMSListActivity.class);
				switch(arg2){
				case 0:
					intent.putExtra("selCategory", "friendship");
					intent.putExtra("isHindi", viewAnimator.getDisplayedChild());
					break;
				case 1:
					intent.putExtra("selCategory", "love");
					intent.putExtra("isHindi", viewAnimator.getDisplayedChild());
					break;
				case 2:
					intent.putExtra("selCategory", "shayri");
					intent.putExtra("isHindi", viewAnimator.getDisplayedChild());
					break;
				case 3:
					intent.putExtra("selCategory", "joke");
					intent.putExtra("isHindi", viewAnimator.getDisplayedChild());
					break;
				case 4:
					intent.putExtra("selCategory", "other");
					intent.putExtra("isHindi", viewAnimator.getDisplayedChild());
					break;
				
				}
				
				startActivity(intent);
			}
		});
      
      mSmsCategoriesListEnglish
		.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				Intent intent = new Intent(MainActivity.this,
						SMSListActivity.class);
				switch(arg2){
				case 0:
					intent.putExtra("selCategory", "friendship");
					intent.putExtra("isHindi", viewAnimator.getDisplayedChild());
					break;
				case 1:
					intent.putExtra("selCategory", "love");
					intent.putExtra("isHindi", viewAnimator.getDisplayedChild());
					break;
				case 2:
					intent.putExtra("selCategory", "shayri");
					intent.putExtra("isHindi", viewAnimator.getDisplayedChild());
					break;
				case 3:
					intent.putExtra("selCategory", "joke");
					intent.putExtra("isHindi", viewAnimator.getDisplayedChild());
					break;
				case 4:
					intent.putExtra("selCategory", "other");
					intent.putExtra("isHindi", viewAnimator.getDisplayedChild());
					break;
				
				}
				
				startActivity(intent);
			}
		});
    }

}
